#!/usr/bin/env bash

set -e -u -x
source ./tasks/helpers.sh
set +x

files=()
while IFS='' read -r line; do files+=("$line"); done < <(git grep -El '^#!(/bin/sh|/bin/bash|/usr/bin/env sh|/usr/bin/env sh)' || true)
if [ -n "${files:-}" ]; then
  echo "Use '/usr/bin/env bash' shebang for following files:"
  printf '  %s\n' "${files[@]}"
  exit 1
fi

files=()
while IFS='' read -r line; do files+=("$line"); done < <(git grep -El '^#!/usr/bin/env bash')
while IFS='' read -r line; do files+=("$line"); done < <(git ls-files | grep '\.sh$')
set -x
"$TEST_INSTALL_PREFIX/bin/shellcheck" "${files[@]}"
